package com.mdinfo.base.advice;

import com.mdinfo.base.annotation.CCLogger;
import com.mdinfo.base.common.bean.MemberInfo;
import com.mdinfo.base.utils.SystemUtil;
import com.mdinfo.base.utils.TimeUtil;
import org.apache.logging.log4j.core.config.Order;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by Administrator on 2017/12/7.
 * 用户操作日志
 */
@Aspect
@Order(2)
@Service
public class LoggerAdvice {

    private Logger logger = LoggerFactory.getLogger(LoggerAdvice.class);

    @Before(value = "@annotation(ccLogger)")
    public void before(JoinPoint joinPoint, CCLogger ccLogger){
        MemberInfo info = SystemUtil.getInfo();
        String time = TimeUtil.formater(new Date());
        logger.info("<"+info.getUsername()+">["+time+"]"+ccLogger.value());
    }
}
